package Demo5;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class CountLowerCaseA extends Thread{
    private static final Object lock = new Object();
    @Override
    public void run() {
        synchronized (lock) {
            for (char c = 'a'; c <= 'e'; c++) {
                int count = 0;
                File folder = new File("D:/text/" + c);
                File[] files = folder.listFiles();
                for (File file : files) {
                    try (FileReader reader = new FileReader(file)) {
                        int fileChar;
                        while ((fileChar = reader.read()) != -1) {
                            if (fileChar == 'a') {
                                count++;
                                break;
                            }
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("Number of files containing 'a' in folder " + c + ": " + count);
            }
        }
    }
}
